import React, { Component } from 'react'
import {bindActionCreators} from "redux"
import * as action from "../action/index.js"
import {connect} from "react-redux" //将仓库数据提供给组件
class Home extends Component {
 componentDidMount(){
     this.props.getList()
 }
 goDetail(item){
     this.props.history.push({
         pathname:"/detail",
         state:{
             del:item
         }
     })
 }
  render() {
    console.log(this.props)
    return (
      <div className='home-wrap'>
          {
              this.props.arr&&this.props.arr.length?this.props.arr.map((item,index)=>{
                  return (
                      <div key={index} onClick={this.goDetail.bind(this,item)}>
                          <img src={item.img} alt="" />
                          <div>
                              <p>价格：{item.price}</p>
                              <p>商品名：{item.title}</p>
                          </div>
                      </div>
                  )
              }):"暂无数据"
          }
      </div>
    )
  }
}
let mapStateToProps = (state)=>{
    return {
        ...state.ShopReduer
    }
}
let mapDisPatchToProps = (dispatch)=>bindActionCreators(action,dispatch)
export default connect(mapStateToProps,mapDisPatchToProps)(Home)